<template>
  <div class="update-gender">
    <van-picker show-toolbar :columns="columns" @cancel="$emit('close')" @confirm="onConfirm" />
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user.js'
export default {
  name: 'updateGender',

  data() {
    return {
      // 性别选择内容
      columns: ['男', '女'],
      // 选中的索引
      localGender: 0
    }
  },

  props: {
    // 输入框内容
    value: {
      type: Number,
      required: true
    }
  },

  methods: {
    // 修改性别操作
    async onConfirm(value, index) {
      this.localGender = index
      await updateUserProfile({ gender: this.localGender })
      this.$toast.success('修改成功')
      this.$emit('close')
      // 通知父组件修改昵称
      this.$emit('input', this.localGender)
    }
    // 选中性别的回调
    // onPickerChange(picker, value, index) {
    //   this.localGender = index
    // }
  }
}
</script>

<style lang="less" scope>
</style>
